<script>
import {slotChildren} from './renderChildren'


export default {
  name: 'query-item',
  props: {
    data: Object,
    model: Object,
    dicts: Object
  },
  render(h) {

    const dict = this.dicts[this.data.dictType || '']

    let options = []
    if(this.data.dataType === 'static') {
      options = this.data.options
    } else {
      options = dict || []
    }
    const children = slotChildren(h, this.data.tag, options)

    const dataObject = {
      attrs: {
        placeholder: this.data.placeholder || this.data.label,
      },
      props: {
        options: options,
        value: this.model[this.data.prop],
        clearable: true,
        props: {}
      },
      on: {
        input: (val) => {
          this.model[this.data.prop] = val
          this.$emit('input', val)
        }
      }
    }

    if(this.data.tag === 'el-date-picker') {
      dataObject.props.valueFormat = 'yyyy-MM-dd'
    }
    if(this.data.tag === 'el-cascader') {
      dataObject.props.props.checkStrictly = true
    }

    return h(this.data.tag, dataObject, children)
  }
}
</script>

